package demo.test;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.chain.ChainMapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.MultipleInputs;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import demo.mapper.BaseMapper;
import demo.mapper.MultFirstMapper;
import demo.mapper.MultSecondMapper;
import demo.reducer.BaseReducer;

public class BaseJob {
	public static void main(String[] args) throws Exception {
		System.setProperty("hadoop.home.dir", "D:/hadoop-2.6.4");
		Configuration cfg = new Configuration();
		
	//	cfg.set("mapred.job.tracker", "192.168.0.176:50020");
		
		Job job = Job.getInstance(cfg, "demo");
		job.setJarByClass(BaseJob.class);
		ChainMapper.addMapper(job, BaseMapper.class, LongWritable.class,Text.class, Text.class, IntWritable.class,new Configuration());
		
		//MultipleInputs.addInputPath(job, new Path("hdfs://192.168.0.176:8020/max.txt"), TextInputFormat.class,MultFirstMapper.class);
		
		//MultipleInputs.addInputPath(job, new Path("d:/demo.txt"), TextInputFormat.class, BaseMapper.class);
		
		job.setMapperClass(ChainMapper.class);
		job.setCombinerClass(BaseReducer.class);
		job.setReducerClass(BaseReducer.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		//FileInputFormat.addInputPath(job, new Path("hdfs://192.168.0.176:8020/max.txt"));
		FileInputFormat.addInputPath(job, new Path("d:/demo.txt"));
		//Path path = new Path("hdfs://192.168.0.176:8020/demo/mulit4");
		FileOutputFormat.setOutputPath(job, new Path("d:/xx"));
		//path.getFileSystem(cfg).delete(path, true);
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
